//
//  String + Extensions.swift
//  WeiBo
//
//  Created by DDC on 2017/9/23.
//  Copyright © 2017年 DDC. All rights reserved.
//

import Foundation

extension String {
    
    func jcl_herf() -> (link:String,text:String)? {
        //"<a href=\"http://app.weibo.com/t/feed/6vtZb0\" rel=\"nofollow\">微博 weibo.com</a>"
        
        // 匹配方案
        let pettern = "<a href=\"(.*?)\" rel=\"nofollow\">(.*?)</a>"
        // 创建正则表达式
        guard let regx = try? NSRegularExpression(pattern: pettern, options: []) ,
        let result = regx.firstMatch(in: self, options: [], range: NSRange(location: 0, length: self.characters.count))
        else {
                return nil
        }
        let link = (self as NSString).substring(with: result.rangeAt(1))
        let text = (self as NSString).substring(with: result.rangeAt(2))
        
        // 返回元祖
        return (link,text)
        
    }
    
    
}
